﻿using System;
using System.Windows.Data;

namespace AnthStat.WPF.Applications.Converters
{
    public sealed class MonthsStringFormatter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // TODO: Code contracts

            if (value == null)
            {
                return String.Empty;
            }

            string text = parameter.ToString();

            double months;
            bool success = Double.TryParse(value.ToString(), out months);
            if (success)
            {
                string textParameter = months.ToString("0.0");
                return String.Format(text.Trim(), textParameter);
            }
            else
            {
                return String.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
